import { _mallStore } from '@/store/config'

export interface FilterTimesRow {
    label: string
    value: string[]
    hide?: boolean
}

interface FilterTimesArray {
    [props: string]: FilterTimesRow[]
}

export const getFilterTimeParams = (type: string) => {
    const value: FilterTimesRow[] = getFilterTimeValue(type);
    let params: { [props: string]: string } = {};
    if (value) {
        for (let row of value) {
            if (!row.hide) {
                for (let key of row.value) {
                    params[key] = '';
                }
            }
        }
    }
    return params;
}

export const getFilterTimeValue = (type: string): FilterTimesRow[] => {
    const { isPaidMember, isGroupManagementPage } = _mallStore;
    const isMallEditionText: string = isGroupManagementPage ? '集团' : '商场';
    const filters: FilterTimesArray = {
        member: [
            { label: `${isMallEditionText}入会时间`, value: ['created_start_at', 'created_end_at'] },
            { label: '到期时间', hide: !isPaidMember, value: ['premium_start_at', 'premium_end_at'] },
        ],
        integral: [
            { label: '积分变动时间', value: ['created_start_at', 'created_end_at'] },
        ],
        consume: [
            { label: '消费时间', value: ['paid_start_at', 'paid_end_at'] },
        ],
        memberGrouping: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
            { label: '更新时间', value: ['updated_start_at', 'updated_end_at'] },
        ],
        black: [
            { label: `${isMallEditionText}入会时间`, value: ['joined_start_at', 'joined_end_at'] },
            { label: '移入黑名单时间', value: ['created_start_at', 'created_end_at'] },
        ],
        logoutRecord: [
            { label: `${isMallEditionText}入会时间`, value: ['joined_start_at', 'joined_end_at'] },
            { label: '注销时间', value: ['created_start_at', 'created_end_at'] },
        ],
        coupon: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
            { label: '发放时间', value: ['sended_start_at', 'sended_end_at'] },
        ],
        couponReport: [
            { label: '领取时间', value: ['created_start_at', 'created_end_at'] },
            { label: '使用时间', value: ['verified_start_at', 'verified_end_at'] },
        ],
        wxCoupon: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
            { label: '可用开始时间', value: ['available_start_at', 'available_end_at'] },
        ],
        goodsActivity: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
            { label: '售卖时间', value: ['sell_start_at', 'sell_end_at'] },
        ],
        cloudFlashPay: [
            { label: '可用时间', value: ['valid_start_at', 'valid_end_at'] },
            { label: '售卖时间', value: ['sell_start_at', 'sell_end_at'] },
        ],
        thirdPartyCoupons: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
        ],
        pointGoods: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
            { label: '兑换时间', value: ['sell_start_at', 'sell_end_at'] },
        ],
        game: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
            { label: '实际结束时间', value: ['finished_start_at', 'finished_end_at'] },
            { label: '活动有效期', value: ['campaign_start_at', 'campaign_end_at'] },
        ],
        recommend: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
        ],
        senseSendCoupon: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
            { label: '发券时间', value: ['send_start_at', 'send_end_at'] },
        ],
        downloadCenter: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
        ],
        ticketVerify: [
            { label: '消费时间', value: ['paid_start_at', 'paid_end_at'] },
            { label: '提交审核时间', value: ['created_start_at', 'created_end_at'] },
            { label: '审核时间', value: ['updated_start_at', 'updated_end_at'] },
        ],
        parkCoupon: [
            { label: '创建时间', value: ['created_start_at', 'created_end_at'] },
            { label: '发放时间', value: ['sended_start_at', 'sended_end_at'] },
        ],
        parkForms: [
            { label: '缴费时间', value: ['paid_start_at', 'paid_end_at'] },
            { label: '入场时间', value: ['entered_start_at', 'entered_end_at'] },
            { label: '离场时间', value: ['exited_start_at', 'exited_end_at'] },
        ],
        goodsShelves: [
            { label: '售卖时间', value: ['sell_start_at', 'sell_end_at'] },
        ],
        exchangeOrder: [
            { label: '核销时间', value: ['verified_start_at', 'verified_end_at'] },
            { label: '兑换时间', value: ['paid_start_at', 'paid_end_at'] },
        ],
        warningRecord: [
            { label: '预警时间', value: ['start_at', 'end_at'] },
        ],
    }
    const returnFilters: FilterTimesRow[] = [];
    for (let row of filters[type]) {
        if (!row.hide) {
            returnFilters.push(row);
        }
    }
    return returnFilters;
}